% Chakram is a subproject of Hexena - Haskell Executable Analyser
% License:			GPL-3
% Maintainer:		Montez Fitzpatrick
% Stability:		Experimental
% Portability:		GHC
% Module:			Hexena.Data.OptionalHeader.X86

This is for the x86 Instruction Set for PE Files.

\begin{code}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Hexena.Data.OptionalHeader.X86 (X86(..)) where

import Data.Label -- Needs 'fclabels' package
import Data.Word

import Hexena.Data.OptionalHeader.DataDirectory (DataDirectory(..))

-- | Representation of the Optional Header format.  Perhaps it would be better to use
--   smart constructors instead.
data X86 = X86
  { 
  -- | State of image file
    _magic :: Word16
  -- | Major version number of linker
  , _majorLinkerVersion :: Word8
  -- | Minor version number of linker
  , _minorLinkerVersion :: Word8
  -- | Size of code section in bytes or sum of all code sections if there are
  --   multiple code sections.
  , _sizeOfCode :: Word32
  -- | Size of the initialized data section, in bytes, or the sum of all such
  --   sections if there are multiple initialized data sections.
  , _sizeOfInitData :: Word32         
  -- | Size of the uninitialized data section, in bytes, or the sum of all such
  --   sections if there are multiple initialized data sections
  , _sizeOfUnInitData :: Word32
  -- | A pointer to the entry point function, relative to the image base address. 
  --   For executable files, this is the starting address. For device 
  --   drivers, this is the address of the initialization function. 
  --   The entry point function is optional for DLLs. When no entry 
  --   point is present, this member is zero.
  , _addrEntryPoint :: Word32
  -- | A pointer to the beginning of the code section, relative to the image base.
  , _baseOfCode :: Word32
  -- | Preferred address of the first byte of the image when it is 
  --   loaded in memory. This value is a multiple of 64K bytes. 
  --   The default value for DLLs is 0x10000000. The default value for 
  --   applications is 0x00400000, except on Windows CE where it is 0x00010000.
  , _imageBase :: Word32
  -- | Alignment of sections loaded in memory, in bytes. This value
  --   must be greater than or equal to the FileAlignment member. 
  --   The default value is the page size for the system.
  , _sectionAlign :: Word32
  -- | Alignment of the raw data of sections in the image file, in bytes. 
  --   The value should be a power of 2 between 512 and 64K (inclusive). 
  --   The default is 512. If the SectionAlignment member is less than the 
  --   system page size, this member must be the same as SectionAlignment.
  , _fileAlign :: Word32
  -- | Major version of the Operating System.
  , _majorOSVersion :: Word16
  -- | Minor version number of the required operating system.
  , _minorOSVersion :: Word16
  -- | Major version number of the image.
  , _majorImgVersion :: Word16
  -- | Minor version number of the image.
  , _minorImgVersion :: Word16
  -- | Major version number of the image.
  , _majorSubsystemVersion :: Word16
  -- | Minor version number of the image.
  , _minorSubsystemVersion :: Word16
  -- | This member is reserved and must be 0.
  , _win32VersionValue :: Word32
  -- | The size of the image, in bytes, including all headers. Must be a 
  --   multiple of SectionAlignment.
  , _sizeOfImage :: Word32
  -- | The combined size of the following items, rounded to a multiple of the 
  --   value specified in the FileAlignment member (4 byte signature, 
  --   size of IMAGE_FILE_HEADER, size of optional header, size of all sections)
  , _sizeOfHeaders :: Word32
  -- | The image file checksum. The following files are validated at load 
  --   time: all drivers, any DLL loaded at boot time, and any DLL loaded 
  --   into a critical system process.
  , _checkSum :: Word32
  -- | The subsystem required to run this image.
  , _subsystem :: Word16
  -- | The subsystem required to run this image.
  , _dllChar :: Word16
  -- | The number of bytes to reserve for the stack. Only the memory specified 
  --   by the SizeOfStackCommit member is committed at load time; the rest 
  --   is made available one page at a time until this reserve size is reached.
  , _sizeOfStackReserve :: Word32
  -- | The number of bytes to commit for the stack.
  , _sizeOfStackCommit:: Word32
  -- | The number of bytes to reserve for the local heap. Only the memory 
  --   specified by the SizeOfHeapCommit member is committed at load time; 
  ---  the rest is made available one page at a time until this reserve 
  --   size is reached.
  , _sizeOfHeapReserve :: Word32
  -- | The number of bytes to commit for the local heap.
  , _sizeOfHeapCommit :: Word32
  -- | This member is obsolete.
  , _loaderFlags :: Word32
  -- | The number of directory entries in the remainder of the optional header. 
  --   Each entry describes a location and size.
  , _numOfRvaSizes :: Word32
  -- | Data directory structure
  , _dataDirectory :: DataDirectory
  } 
  deriving (Show, Eq, Ord)

mkLabel ''X86
\end{code}
